//
//  PresentAnimationClass.m
//  Model
//
//  Created by caohanchao on 2017/6/5.
//  Copyright © 2017年 YDJH. All rights reserved.
//

#import "PresentAnimationClass.h"

@implementation PresentAnimationClass

+ (void)transitionWithType:(AnimationType)type withAnimationDirection:(AnimationDirection)animationDirection duration:(NSTimeInterval)duration fromVC:(UIViewController *)fromViewController toVC:(UIViewController *)toViewController
{
    
    //创建CATransition对象
    
    CATransition *animation = [CATransition animation];
    
    NSString *animationType = kCATransitionFade;
    
    //设置运动时间
    
    animation.duration = duration ? duration : 1.f;
    
    switch (type) {
            
        case AnimationTypeFade://淡入淡出
        {
            
            animationType =kCATransitionFade;
            
        }
            
            break;
            
        case AnimationTypePush://推挤
            
        {
            
            animationType =kCATransitionPush;
            
        }
            
            break;
            
        case AnimationTypeReveal://揭开
            
        {
            
            animationType =kCATransitionReveal;
            
        }
            
            break;
            
        case AnimationTypeMoveIn://覆盖
            
        {
            
            animationType =kCATransitionMoveIn;
            
        }
            
            break;
            
        case AnimationTypeCube://立方体
            
        {
            
            animationType =@"cube";
            
        }
            
            break;
            
        case AnimationTypeSuckEffect://吮吸
            
        {
            
            animationType =@"suckEffect";
            
        }
            
            break;
            
        case AnimationTypeOglFlip://翻转
            
        {
            
            animationType =@"oglFlip";
            
        }
            
            break;
            
        case AnimationTypeRippleEffect://波纹
            
        {
            
            animationType =@"rippleEffect";
            
        }
            
            break;
            
        case AnimationTypePageCurl://翻页
            
        {
            
            animationType =@"pageCurl";
            
        }
            
            break;
            
        case AnimationTypePageUnCurl://反翻页
            
        {
            
            animationType =@"pageUnCurl";
            
        }
            
            break;
            
        case AnimationTypeCameraIrisHollowOpen://开镜头
            
        {
            
            animationType =@"cameraIrisHollowOpen";
            
        }
            
            break;
            
        case AnimationTypeCameraIrisHollowClose://关镜头
            
        {
            
            animationType =@"cameraIrisHollowClose";
            
        }
            
            break;
            
        case AnimationTypeCurlDown://下翻页
            
        {
            
            animationType =@"pageUnCurl";
            
        }
            
            break;
            
        case AnimationTypeCurlUp://上翻页
            
        {
            
            animationType =@"pageUnCurl";
            
        }
            
            break;
            
        case AnimationTypeFlipFromLeft://左翻转
            
        {
            
            animationType =@"pageUnCurl";
            
        }
            
            break;
            
        case AnimationTypeFlipFromRight://右翻转
            
        {
            
            animationType =@"pageUnCurl";
            
        }
            
            break;
            
        default:
            
            break;
            
    }
    
    NSString *subtype = kCATransitionFromRight;
    
    switch (animationDirection) {
            
        case AnimationDirectionBottom:
            
        {
            
            subtype =kCATransitionFromBottom;
            
        }
            
            break;
            
        case AnimationDirectionLeft:
            
        {
            
            subtype =kCATransitionFromLeft;
            
        }
            
            break;
            
        case AnimationDirectionRight:
            
        {
            
            subtype =kCATransitionFromRight;
            
        }
            
            break;
            
        case AnimationDirectionTop:
            
        {
            
            subtype =kCATransitionFromTop;
            
        }
            
            break;
            
        default:
            
            break;
            
    }
    
    //设置运动type
    
    animation.type = animationType;
    
    if (subtype != nil) {
        
        //设置子类
        
        animation.subtype = subtype;
        
    }
    
    //设置运动速度
    
    animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
    
    [fromViewController.view.window.layer addAnimation:animation forKey:@"animation"];
    
    [fromViewController presentViewController:toViewController animated:NO completion:nil];
    
}

@end
